package org.dromara.common.arthas.context;

import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * @description:
 * @author: zhou shuai
 * @date: 2024/7/22 16:27
 * @version: v1
 */
public class ArthasApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {

    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {
        ConfigurableEnvironment environment = applicationContext.getEnvironment();
        String applicationName = environment.getProperty("spring.application.name");
        String arthasLogPath = "/logs/arthas/" + applicationName;
        // 修改arthas日志文件路径
        System.setProperty("ARTHAS_LOG_PATH", arthasLogPath);
        System.setProperty("RESULT_LOG_FILE", arthasLogPath + "/arthas-cache/result.log");
    }

}
